﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Library;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace SimulationGame
{
	class WorldScreen:GameScreen
	{
		public enum Size { Small=100, Medium=200, Big=300 };
		public enum Resources { Sparse=200, Medium=500, Filled=800 };
		public enum Enemies { Sparse, Medium, Filled };

		public WorldScreen(Size size,Resources resourcesAmount):base(false,false)
		{
			GameObjectsRegistry.tileMap = new TileMap((int)size, (int)size, (int)resourcesAmount);
			
		}
		public override void LoadContent()
		{
			if (content == null)
			{
				content = new ContentManager(screenManager.Game.Services, "Content/");
			}
            TextureRegistry.Initialize(content);
			GameObjectsRegistry.tileMap.Generate();

			for (int x = 0; x < GameObjectsRegistry.tileMap.width; x++)
			{
				for (int y = 0; y < GameObjectsRegistry.tileMap.height; y++)
				{
					Add(GameObjectsRegistry.tileMap.getTile(x, y));
				}
			}
			GameObjectsRegistry.civilizations["Player"] = new Civilization(1, new Vector2(1, 1));
			AddLight(new LightSource(new Vector2(GameSettings.GetResolution().X / 2, 100), Color.White, 3000));
			AddCivilization(GameObjectsRegistry.civilizations["Player"]);
		}
		public void AddCivilization(Civilization civilization)
		{
			foreach (Human human in civilization.humans)
			{
				Add(human);
			}
		}
		public override void HandleInput(InputState inputState)
		{
			foreach (KeyValuePair<string, Civilization> civ in GameObjectsRegistry.civilizations)
			{
				foreach (Human human in civ.Value.humans)
				{
					human.HandleInput(inputState);
				}
			}
			GameObjectsRegistry.tileMap.HandleInput(inputState);
		}
		public override void Update(GameTime gameTime)
		{
			foreach (KeyValuePair<string,Civilization> civ in GameObjectsRegistry.civilizations)
			{
				civ.Value.PerformActions();
			}
		}
	}
}
